/************************************************************************************
**  
* @copyright (c) 2013-2100,  Technology Co., LTD. All Right Reserved.
*
*************************************************************************************/
/**
* @file	    duye_sys_process.h
* @version     
* @brief      
* @author
* @date	    2014-09-28
* @note 
*
*  1. 2014-09-28 Created this file
* 
*/
#pragma once

#include <duye_type.h>

namespace duye {
    
/**
 * @brief system callback observer
 */
class SysProcess {    
public:
    /**
     * @brief signal type
     */
    typedef enum {
        D_SIGSEGV = 1,
        D_SIGINT = 1<<1,
        D_SIG = 1<<2,
        D_SIG_ALL = D_SIGSEGV | D_SIGSEGV
    } SignalType;

public:
    SysProcess();
    ~SysProcess();
    
    /**
     * @brief setting the number of one process can open files
     * @param [in] limitFile : can open file number
     * @return true/false
     */
    bool setLimitFile(const uint32 limitFile);  
    uint32 limitFile() const;
    
private:
    uint32    m_limitFile;
};

/**
 * @brief system callback observer
 */
class ProcessSysCallbackObserver {
public:
    virtual ~ProcessSysCallbackObserver() {}

    /**
     * @brief system signal handler
     * @param [in] sig : signal
     */    
    virtual void onSignalHandler(const SysProcess::SignalType sig) = 0;
};

/**
 * @biref process monitor for system API callback
 */
class ProcessSysCallback {
public:
    ProcessSysCallback();
    ~ProcessSysCallback();
    
    /**
     * @brief regist process system callback observer
     * @param [in] observer : observer
     */
    void registObserver(ProcessSysCallbackObserver* observer);

     /**
     * @brief add signal
     * @param [in] sig : sig value, default is all signal
     */   
    void addSignal(const SysProcess::SignalType sig = SysProcess::D_SIG_ALL);
    
    /**
     * @brief system signal callback
     * @param [in] sig : signal
     */
    static void signalHandler(const int32 sig);

private:
    static ProcessSysCallbackObserver*  m_observer;
};

}
